import { legacy_createStore as createStore, applyMiddleware } from 'redux'
import { getToken } from '@/utils/token'
import { rootReducers } from './reducers'

import thunk from 'redux-thunk'
// import { composeWithDevTools } from 'redux-devtools-extension'

let middleware

if (process.env.NODE_ENV === 'production') {
  middleware = applyMiddleware(thunk)
} else {
  const { composeWithDevTools } = require('redux-devtools-extension')
  middleware = composeWithDevTools(applyMiddleware(thunk))
}

const InitialState = {
  login: getToken(),
}

const store = createStore(rootReducers, InitialState, middleware)

export default store
